package com.seocoo.worker.base.multiImage;

import android.support.constraint.ConstraintLayout;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.widget.ImageView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.seocoo.worker.R;
import com.seocoo.worker.base.ImageLoaderEngine;
import com.sfh.lib.AppCacheManager;


/**
 * Created by: ssp
 * Date: 2020/4/14 19:09
 * Description:  多张图片
 */
public class BaseListImageAdapter extends BaseQuickAdapter<RspImage, BaseViewHolder> {
    private boolean delete = false;

    public BaseListImageAdapter(boolean delete) {
        super(R.layout.base_image_list_item);
        this.delete = delete;
    }

    @Override
    protected void convert(BaseViewHolder helper, RspImage item) {
        helper.addOnClickListener(R.id.iv_delete);
        ImageView view = helper.getView(R.id.iv_image);
        String imgUrl = item.fullPath;
        if (TextUtils.equals("-1", imgUrl)) {
            helper.setGone(R.id.iv_delete, false);
            initViews(view, 27, 25);
            view.setImageResource(R.drawable.base_photo);
        } else {
            if (delete) {
                helper.setGone(R.id.iv_delete, true);
            } else {
                helper.setGone(R.id.iv_delete, false);
            }
            initViews(view, 100, 100);
            new ImageLoaderEngine(imgUrl).into(view);
        }
    }

    private void initViews(ImageView view, int wDp, int hDp) {
        DisplayMetrics displayMetrics = AppCacheManager.getApplication().getResources().getDisplayMetrics();
        float dp = displayMetrics.density;
        ConstraintLayout.LayoutParams params = new ConstraintLayout.LayoutParams((int) (wDp * dp + 0.5), (int) (hDp * dp + 0.5));
        params.topToTop = ConstraintLayout.LayoutParams.PARENT_ID;
        params.bottomToBottom = ConstraintLayout.LayoutParams.PARENT_ID;
        params.rightToRight = ConstraintLayout.LayoutParams.PARENT_ID;
        params.leftToLeft = ConstraintLayout.LayoutParams.PARENT_ID;
        view.setLayoutParams(params);
    }
}
